package diploma.kisel.modelas.gui.common;

import java.awt.Component;
import java.awt.event.MouseEvent;

import javax.swing.JOptionPane;
import javax.swing.JTable;

import diploma.kisel.modelas.domain.Computer;
import diploma.kisel.modelas.domain.ComputerType;
import diploma.kisel.modelas.domain.Database;
import diploma.kisel.modelas.domain.Device;
import diploma.kisel.modelas.service.DeviceTypeServiceImpl;
import diploma.kisel.modelas.service.api.DeviceTypeService;

public class TablesService {
	
	private static DeviceTypeService deviceTypeService = new DeviceTypeServiceImpl();
	
	public static Computer getPCFromTable(JTable table, int row) {
		Computer computer = new Computer();
		computer.setId((Integer) table.getValueAt(row, 0));
		computer.setNumber((String) table.getValueAt(row, 1));
		computer.setBrand((String) table.getValueAt(row, 2));
		computer.setCost((Integer) table.getValueAt(row, 3));
		computer.setFeatures((String) table.getValueAt(row, 4));
		computer.setType((ComputerType) table.getValueAt(row, 5));
		return computer;
	}
	
	public static Device getDeviceFromTable(JTable table, int row) {
		Device device = new Device();
		device.setId((Integer) table.getValueAt(row, 0));
		device.setNumber((String) table.getValueAt(row, 1));
		device.setBrand((String) table.getValueAt(row, 2));
		device.setCost((Integer) table.getValueAt(row, 3));
		device.setFeatures((String) table.getValueAt(row, 4));
		String deviceTypeId = (String) table.getValueAt(row, 5);
		device.setDeviceType(deviceTypeService
				.findById(deviceTypeId));
		return device;
	}
	
	public static Database getDatabaseFromTable(JTable table, int row) {
		Database database = new Database();
		database.setId((Integer) table.getValueAt(row, 0));
		database.setNumber((String) table.getValueAt(row, 1));
		database.setCountOfTables((Integer) table.getValueAt(row, 2));
		database.setCountOfCreationDays((Integer) table.getValueAt(row, 3));
		database.setCost((Integer) table.getValueAt(row, 4));
		return database;		
	}
	
}
